package com.yyy.instagram.common.PullRefreshHeader;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.yyy.instagram.R;

import static android.R.attr.radius;

/**
 * Created by qqqqqqq on 2016/9/28.
 */

public class PreRefreshView extends View {

    private Paint paintQ;
    private Paint paintH;

    private float progress = 34;
    public float max = 100;
    RectF oval;

    public PreRefreshView(Context context) {
        super(context);
        initView();
    }

    public PreRefreshView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public PreRefreshView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    protected  void initView(){

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(paintQ == null) {
            paintQ = new Paint();
            paintQ.setColor(getResources().getColor(R.color.grayqian));
            paintQ.setStyle(Paint.Style.STROKE);
            paintQ.setStrokeWidth(5);
            paintQ.setAntiAlias(true);
        }
        if(paintH == null) {
            paintH = new Paint();
            paintH.setColor(getResources().getColor(R.color.grayShen));
            paintH.setStrokeWidth(5);
            paintH.setStyle(Paint.Style.STROKE);
            paintH.setAntiAlias(true);
        }
        int widthCenter = getWidth()/2;
        int heightCenter = getHeight()/2;
        int radius = (int) (50 - 10/2);

        oval = new RectF(widthCenter - radius, heightCenter - radius, widthCenter
                + radius, heightCenter + radius);

        canvas.drawCircle(widthCenter,heightCenter, radius, paintQ);
        canvas.drawArc(oval, 270, 360 * progress / max, false, paintH);
    }

    public void setProgress(float progress){
        this.progress = progress;
        invalidate();
    }

}
